package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Event;
import com.ruoyi.system.service.IEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 活动管理Controller
 * 
 * @author ruoyi
 * @date 2022-12-25
 */
@RestController
@RequestMapping("/event")
public class EventController extends BaseController
{
    @Autowired
    private IEventService eventService;





    /**
     * 查询活动管理列表
     */
    @RequiresPermissions("system:event:list")
    @GetMapping("/list")
    public TableDataInfo list(Event event)
    {
        startPage();
        List<Event> list = eventService.selectEventList(event);
        return getDataTable(list);
    }

    /**
     * 导出活动管理列表
     */
    @RequiresPermissions("system:event:export")
    @Log(title = "活动管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Event event)
    {
        List<Event> list = eventService.selectEventList(event);
        ExcelUtil<Event> util = new ExcelUtil<Event>(Event.class);
        util.exportExcel(response, list, "活动管理数据");
    }

    /**
     * 获取活动管理详细信息
     */
    @RequiresPermissions("system:event:query")
    @GetMapping(value = "query/{eid}")
    public AjaxResult getInfo(@PathVariable("eid") Long eid)
    {
        return AjaxResult.success(eventService.selectEventByEid(eid));
    }

    /**
     * 新增活动管理
     */
    @RequiresPermissions("system:event:add")
    @Log(title = "活动管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Event event)
    {
        return toAjax(eventService.insertEvent(event));
    }

    /**
     * 修改活动管理
     */
    @RequiresPermissions("system:event:edit")
    @Log(title = "活动管理", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody Event event)
    {
        return toAjax(eventService.updateEvent(event));
    }

    /**
     * 删除活动管理
     */
    @RequiresPermissions("system:event:remove")
    @Log(title = "活动管理", businessType = BusinessType.DELETE)
	@DeleteMapping("remove/{eids}")
    public AjaxResult remove(@PathVariable Long[] eids)
    {
        return toAjax(eventService.deleteEventByEids(eids));
    }





}
